package com.aaa.javaweb.dao.impl;

import com.aaa.javaweb.dao.ZongDao;
import com.aaa.javaweb.until.JDBCUntil;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ZongDaoImpl implements ZongDao {
    @Override
    public Map<Object, Object> getzong() {
        int minMonth=1;
        int maxMonth=12;
        //MONTH(createtime)>=1 and MONTH(createtime)<=12 GROUP BY MONTH(createtime)
        String sql="select MONTH(createtime),sum(price) from t_order where MONTH(createtime)>=1 and MONTH(createtime)<=12 GROUP BY MONTH(createtime)";
        List<Map> maps = JDBCUntil.selectMap(sql);
        Map<Object, Object> map1 = new HashMap<>(64);


        List<Object> monthData = new ArrayList<>();

        // 装填入库金额的list
        List<Double> ruKuMoney = new ArrayList<>();
        for(int i=minMonth;i<=maxMonth;i++){
            double value=0;
            monthData.add(i+"");
            for (Map map : maps) {
                if(Integer.parseInt(map.get("MONTH(createtime)")+"")==i){
                    value=Double.parseDouble(map.get("sum(price)")+"");
                }
            }
            ruKuMoney.add(value);
        }
        map1.put("monthData",monthData);
        map1.put("ruKuMoney",ruKuMoney);

        return map1;
    }

    @Override
    public List<Map> gettype() {

        //String sql="select sum(o.price) value , t.tname as name from t_order o left join t_type t on o.roomtype=t.id GROUP BY t.tname ";
        String sql1="SELECT SUM(tr.price) value,tp.tname AS name from t_order tr,t_type tp WHERE tr.roomtype = tp.id and tr.status!=3 GROUP BY tr.roomtype ";
        return JDBCUntil.selectMap(sql1);
    }
}
